package com.example.leetcode.leetcode.hot100;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haitao
 * @date 2021/11/2 11:44 上午
 * 回溯求数组子集
 * {1,2,3}
 * {},{1,2,3},{1,2}
 * <p>
 * 1,2,3
 */
public class Solution78 {
    /**
     * 回溯临时数组
     */
    List<Integer> t = new ArrayList<>();
    /**
     * 结果
     */
    List<List<Integer>> ans = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        dfs(0,nums);
        return ans;
    }

    public void dfs(int cur, int[] nums) {
        if (cur == nums.length) {
            ans.add(new ArrayList<>(t));
            return;
        }
        t.add(nums[cur]);
        dfs(cur+1,nums);
        t.remove(t.size() - 1);
        dfs(cur+1,nums);
    }


    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3};
        System.out.println(new Solution78().subsets(nums));
    }

}
